Interface and Application Programming

Texto Justificado

Group assignment:

  • Send a message between two projects.
  • Document your work to the group work page and reflect on your individual page what you learned.

Individual assignments

  • design, build and connect wired or wireless node(s) with network or bus addresses and a local interface.

Group Assignment

  • Here is the link where you can see the development of the week's group assignment.Group Assignment

For our group project, we decided to carry out an exhaustive study of different programming languages. Personally, I focused on learning Flutter, a cross-platform mobile app development framework. This experience turned out to be very enriching, as I was able to delve deeper into the development of interactive and efficient user interfaces for mobile devices.

The process involves downloading the Processing installation file from the official website. Then, using the command line (CMD), we navigate to the location of the downloaded file, unzip it, and run the installer to complete the installation of Processing on the system. Once installed, we can verify the installation by opening the program from the command line. This method is useful if you prefer to work with the command line or need to perform the installation remotely or automated.

Imagen


Imagen

After installing Processing and if you want to work with Visual Studio Code (VS Code) as your development environment, the next step would be to install the Processing extension or plugin for VS Code. This will allow you to write and run Processing code directly from VS Code.


Imagen


Imagen


For this week's task, we were studying a language as a team and we explained its benefits. Each of us shared what we learned and we created a comparative chart.


Imagen

Imagen

During our teamwork, we actively shared and discussed what each of us learned. This collaboration not only strengthened our individual knowledge, but also allowed us to integrate diverse skills and perspectives into our joint project. Through this experience, we managed to unite our efforts and create a more complete and solid work.

Individual assignments

For your individual project, I would recommend using the XIAO RP2040 along with sensors like the MPU6050 and HC-SR04. Additionally, you can use Processing software to visualize interactions with these sensors. Here I detail the steps you can follow:



Imagen

During our teamwork, we actively shared and discussed what each of us learned. This collaboration not only strengthened our individual knowledge, but also allowed us to integrate diverse skills and perspectives into our joint project. Through this experience, we managed to unite our efforts and create a more complete and solid work.

Step 1: Setting Up the Environment

Arduino IDE:

  • Ensure you install support for the XIAO RP2040 in the Arduino IDE to be able to program it.
  • Install the libraries for MPU6050 and HC-SR04 in the Arduino IDE using the Library Manager (Sketch > Include Library > Manage Libraries).
Imagen


Imagen

Step 2: Connecting the Components

Connecting the XIAO RP2040:

  • Use a micro USB cable to connect the XIAO RP2040 to your computer.
  • Connect the MPU6050 to the XIAO RP2040 according to their respective connection diagrams. Refer to datasheets for correct pin connections.
Imagen


Imagen


Step 3: Programming the XIAO RP2040

Writing Code:

  • Open the Arduino IDE and select the XIAO RP2040 as your development board (Tools > Board > Raspberry Pi RP2040).
  • Use example code or write your own code to read data from MPU6050 (acceleration and gyroscope).

Code



Imagen

Step 4: Integration with Processing

Installing Processing:

  • Configure your program on the XIAO RP2040 to send data via the serial port.
  • Write a Processing sketch that reads data from the serial port and visualizes it graphically or interactively.
Imagen


Imagen


Step 5: Testing and Debugging

Installing Processing:

  • Upload your program to the XIAO RP2040 and verify that it functions correctly.
  • Run your Processing sketch and observe the visualization of data coming from the sensors.

First, make sure you have MPU6050 sensor connected to your Arduino board correctly. Use the necessary libraries to communicate with the MPU6050 from Arduino. You can use the Wire.h library for I2C communication and the MPU6050.h library to interface with the sensor.

Code: Example 1



To reflect acceleration data in X, Y, and Z on a graphical platform while the program is running in Processing, you can use simple visualization shapes like rectangles or ellipses that move according to the data values.



Imagen


Imagen


You can adjust the scale of the x and y values ​​received from the serial port to enlarge the display in the window. For example, you can multiply values ​​by a scaling factor to increase their on-screen size. This will allow you to see the trajectory better even if the values ​​are small.

Code: Example 2


Center the Path in the Middle: To ensure that the path is centered in the middle of the window, you can adjust the x and y coordinates when drawing points and lines. Subtract half the width and height of the window from the x and y coordinates respectively to center the path


Imagen


Imagen


If you want to represent movements instead of points as a ball moving along the path generated by the data received from the serial port, you can modify the code to draw and move a ball (ellipse or ellipseMode(CENTER)) in instead of using lines or points. Here I show you how you can adapt the code to achieve this effect


Code: Example 3


Imagen


Imagen



Here is an improved version of the code that focuses on displaying the sphere representing the movement inside the cube and tracking the trajectory in real time


HC-SR04 Sensor Connection

Connect the HC-SR04 sensor to your Arduino as follows

  • Connect to 5V on XIAO RP2040
  • GND: Connect to GND on Arduino.
  • Trig: Connect to pin D4 on XIAO
  • Echo: Connect to pin D3 on XIAO
  • Use this code on Arduino to read the distance from the HC-SR04 sensor and send the values ​​through the serial port:
  • Imagen

Code: Example 4


Code in processing

In Processing to track the elapsed time and display the distance during that interval. Here's how you can set the code to display the distance for 2 seconds after receiving new data from the serial port.


Imagen


Imagen




  • LastDataTime: Used to store the time in milliseconds when the last data was received from the serial port.
  • draw():
  • After processing the received string and updating the distance, the current time is recorded using millis().
  • It is checked if less than 2 seconds have passed since the last data update (if (millis() - lastDataTime < 2000)).
  • If so, the distance measured is displayed in the Processing window during the 2 second interval.



Imagen


Imagen


To have a ball drawn in the center of the window and change size as you move closer or further away from the distance sensor connected to the Arduino, you must modify the code so that the position and size of the ball are dynamically updated in function of the measured distance. Here I provide you with a modified version of your code in Processing that includes the graphical representation of a ball in the center of the window. The size of the ball will change depending on the distance measured by the ultrasonic sensor connected to the XIAO RP2040


Imagen


Imagen




To create an effect where the number of beads increases as you get closer to the distance sensor, you can modify the code to generate more beads when the measured distance is shorter. Each ball will have a size proportional to the distance and will appear in a random position around the center of the window.


Imagen


Imagen





In summary

During this week, I learned how to use an interface to interact in real time with sensors, allowing multiple sensors to be controlled at the same time using a microcontroller such as the Seeeduino XIAO. This knowledge opens the door to various applications that we can develop using different sensors. As of week 14, I've explored several programming languages, which has been a lot of fun. Although at first it was a little tedious, with practice I have managed to feel more comfortable and competent in developing projects with these devices.

Links to all working files used this week

1. LED from the Dashboard.zip
1. Acceleromer example 1.pde
2. Acceleromer example 2.pde
3. Acceleromer example 3.pde
4. Distance example 1.pde
5. Distance example 2.pde
6. Distance example 3.pde
6. Accelerometer.ino
6. Distance.ino